package br.com.documentos.model.persistence;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import br.com.documentos.model.entity.Usuario;

@Repository
public class UsuarioRepository extends BaseRepository<Usuario> {

	@Autowired
	public void init(SessionFactory factory) {
	    setSessionFactory(factory);
	}
	
	public Usuario buscarPorEmail( String email ){
		return loadIgnoreCase( "email", email );
	}
	
	public Usuario buscarPorEmailESenha( String email, String senha ){
		DetachedCriteria criteria = createCriteria()
			.add(Restrictions.eq("email", email))
			.add(Restrictions.eq("senha", senha));
		return uniqueResult(criteria);
	}

}

